package org.spiderflow;

import javax.script.Bindings;
import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import java.util.Arrays;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

public class TestGroovy {
    public static void main(String[] args)  throws  Exception{
//        //创建engine实例直接解析文本内容
//        ScriptEngineManager factory = new ScriptEngineManager();
//
//        //每次生成一个engine实例
//        ScriptEngine engine = factory.getEngineByName("groovy");
//        System.out.println(engine.toString());
//        assert engine != null;
//        Bindings binding = engine.createBindings();
//        binding.put("date", new Date());
//
//        //如果script文本来自文件,请首先获取文件内容
//        engine.eval("def getTime(){return date.getTime();}", binding);
//        engine.eval("def sayHello(name,age){return 'Hello,I am ' + name + ',age' + age;}");
//        Long time = (Long) ((Invocable) engine).invokeFunction("getTime", null);
//        System.out.println(time);
//        String message = (String) ((Invocable) engine).invokeFunction("sayHello", "zhangsan", new Integer(12));
//        System.out.println(message);

        String content = "li@zzu.edu.cn ; Lian Weiliang, deputy director of NDRC, who also spoke at the conference, said the scale of the sector has reached 576.2.3 billion yuan ($83.8 billion) last year, a year-on-year increase of 27.9 percent, offering jobs to as many as 30 million people.";
        Pattern specailP = Pattern.compile("[^\\s]+[.][^\\s]+");
        Matcher matcher2 = specailP.matcher(content);
        while(matcher2.find()){
            String key = matcher2.group();
            String modifyStr = key.replaceAll("\\.","#__#");
            content = content.replace(key,modifyStr);
        }

        System.out.println(content);
        System.out.println(content.replaceAll("#__#","\\."));

        String[] testMap={"good item","test","ddd","1212"};
        Arrays.stream(testMap).map(s->s+";").collect(Collectors.toList()).forEach(System.out::println);

    }
}
